package com.resou.reader.bookstore;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.request.RequestOptions;
import com.resou.reader.R;
import com.resou.reader.bookdetail.BookDetailActivity;
import com.resou.reader.data.bookstore.model.PlateNovels;
import com.resou.reader.utils.GalleryAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class VIPGalleryAdapter extends GalleryAdapter {

    private final List<PlateNovels> mNovels;

    @BindView(R.id.imageView)
    ImageView imageView;

    public VIPGalleryAdapter(@NonNull Context context, List<PlateNovels> novels) {
        super(context);
        mNovels = novels;
    }

    @Override
    protected View onInflateLayout(LayoutInflater layoutInflater, ViewGroup container, int position) {
        View view = layoutInflater.inflate(R.layout.recycler_item_type_vip_zone_item, container, false);
        ButterKnife.bind(this, view);

        PlateNovels novels = mNovels.get(position);
        Glide.with(view).setDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)).load(novels.getShowPic()).into(imageView);

        view.setOnClickListener(v -> {
            BookDetailActivity.startDetailActivity(container.getContext(), novels.getNovelId());
        });

        return view;
    }

    @Override
    public int getCount() {
        return mNovels.size();
    }
}